define(function(require, exports){
	var $ = require("jquery");
	var pubjs = require('pubjs');
	var view = require('@base/view');
	var util = require('util');
	var dspUtil = require('dspUtil');
	var popwin	= require('@base/dialog').base;

	var Base = view.widget.extend({
		init:function(config){
			config = pubjs.conf(config, {
				vModel: {
					name: ''
				},
				layout:  {
					module: '@base/dialog.base',
					silence: false,
					title: LANG('更新提示'),
					size: 'm',
					"buttonConfig": {
						// 确定按钮样式
						"ok": {
							"type": "button"
							, "value": LANG("同步更新")
							, "width": 100
						}
					},
					height: 600
				}
			});

			this.Super('init', arguments);
		}
		,afterBuild:function(){
			var target = this.getContainer();
			target.append(
				`
					<div class="">
					<div class="alert a-is-warning tips mb10">
						<em class="uk-icon-exclamation-circle mr10" style="font-size:14px"/>
						<span >#{{name}}# </span>
						<span class="ml10">${LANG('被以下计划推广组引用，确认更新将会同步该素材组内容!')}</span>
					</div>
						<div pub-name="grid" pub-mod="materialGroup/grid/ref.base"></div>
					</div>
				`
			);

			this.buildFromTemplate({
				grid: {}
			});
			this.vm.mount();
		}
		,setData: function (data) {
			this.$.grid.setData(data);
			this.$.grid.calculateWidth();
			return this;
		}
		,setName: function (name) {
			this.vm.$.name = name || '';
			return this;
		}
		,reset: function(){
			this.vm.reset();
			this.$.grid.reset();
			return this;
		}
	});

	exports.ref = Base;

	var Name = popwin.extend({
		init:function(config){
			config = pubjs.conf(config, {
				'title': LANG('保存素材组'),
				'width': 300,
				'showFoot': true,
				'param': null,
				'silence': false,
				'size': 's',
				"sizeDimension": {
					's': {'width': 550, 'minHeight': 200, 'maxHeight': 600},
				}
			});

			this.Super('init', arguments);
		},
		afterBuild:function() {
			this.Super('afterBuild', arguments);
			var target = this.getContainer('body');
			target.append(
				`
					<div class="M-formConGroup">
						<label class="group-label">${LANG('名称')}</label>
						<div class="group-content">
							<span class="P-campaignEditInputWidth" pub-mod="@base/common/input.text" pub-name="name"/>
						</div>
					</div>
				`
			);

			this.buildFromTemplate({
				name: {
					width: 300
				}
			});
		}
		,onOk: function(evt){
			var name = this.$.name.getValue();
			if(!name)
			{
				return pubjs.alert('名字不能为空');
			}

			this.fire("dialogOk", {Name: name});
			return false;
		}
		,reset: function () {
			this.$.name.reset();
			return this;
		}
	});

	exports.name = Name;
});